// user.js - 用户相关API

import axios from '../plugins/axios'

/**
 * 获取当前用户资料
 * @returns {Promise} 返回用户资料
 */
export function getUserProfile() {
  return axios({
    url: '/api/user/profile',
    method: 'get'
  });
}

/**
 * 更新用户资料
 * @param {Object} data 用户资料数据
 * @returns {Promise} 返回更新结果
 */
export function updateUserProfile(data) {
  return axios({
    url: '/api/user/profile',
    method: 'put',
    data
  });
}

/**
 * 修改密码
 * @param {Object} data 密码数据 {oldPassword, newPassword, confirmPassword}
 * @returns {Promise} 返回操作结果
 */
export function changePassword(data) {
  return axios({
    url: '/api/user/change-password',
    method: 'post',
    data: {
      oldPassword: data.old_password || data.oldPassword,
      newPassword: data.new_password || data.newPassword,
      confirmPassword: data.confirm_password || data.confirmPassword || data.newPassword
    }
  });
}

/**
 * 获取用户车辆列表
 * @returns {Promise} 返回车辆列表
 */
export function getUserVehicles() {
  return axios({
    url: '/api/user/vehicles',
    method: 'get'
  });
}

/**
 * 添加车辆信息
 * @param {Object} data 车辆数据
 * @returns {Promise} 返回操作结果
 */
export function addVehicle(data) {
  return axios({
    url: '/api/user/vehicles',
    method: 'post',
    data: {
      plateNumber: data.plateNumber,
      vehicleBrand: data.vehicleBrand,
      vehicleModel: data.vehicleModel,
      vehicleType: data.vehicleType,
      vehicleColor: data.vehicleColor,
      isDefault: data.isDefault
    }
  });
}

/**
 * 更新车辆信息
 * @param {Object} data 车辆数据
 * @returns {Promise} 返回操作结果
 */
export function updateVehicle(data) {
  return axios({
    url: `/api/user/vehicles/${data.id}`,
    method: 'put',
    data: {
      plateNumber: data.plateNumber,
      vehicleBrand: data.vehicleBrand,
      vehicleModel: data.vehicleModel,
      vehicleType: data.vehicleType,
      vehicleColor: data.vehicleColor,
      isDefault: data.isDefault
    }
  });
}

/**
 * 删除车辆信息
 * @param {Number} id 车辆ID
 * @returns {Promise} 返回操作结果
 */
export function deleteVehicle(id) {
  return axios({
    url: `/api/user/vehicles/${id}`,
    method: 'delete'
  });
} 